//
//  CaseTableViewCell.m
//  HomeFurnishing
//
//  Created by dllo on 16/3/25.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "CaseTableViewCell.h"
#import "CaseBaseModel.h"
@implementation CaseTableViewCell

-(void)dealloc
{
    [_imgView release];
    [_title release];
    [_styleShow release];
    [_areaShow release];
    [_typeShow release];
    [_costShow release];
    [_userImgView release];
    [_collectBtn release];
    [super dealloc];
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imgView = [[UIImageView alloc] init];
        //_imgView.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_imgView];
        [_imgView release];
        
        self.title = [[UILabel alloc] init];
        //_title.backgroundColor = [UIColor greenColor];
        _title.font = [UIFont systemFontOfSize:22];
        [self.contentView addSubview:_title];
        [_title release];
        
        self.styleShow = [[UILabel alloc] init];
        //_styleShow.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_styleShow];
        _styleShow.textColor = [UIColor grayColor];
        [_styleShow release];
        
        self.typeShow = [[UILabel alloc] init];
        //_typeShow.backgroundColor = [UIColor blueColor];
        _typeShow.textColor = [UIColor grayColor];
        _typeShow.textAlignment = 1;
        [self.contentView addSubview:_typeShow];
        [_typeShow release];
        
        self.areaShow = [[UILabel alloc] init];
        //_areaShow.backgroundColor = [UIColor brownColor];
        _areaShow.textColor = [UIColor grayColor];
        _areaShow.textAlignment = 1;
        [self.contentView addSubview:_areaShow];
        [_areaShow release];
        
        self.costShow = [[UILabel alloc] init];
        //_costShow.backgroundColor = [UIColor redColor];
        _costShow.textColor = [UIColor grayColor];
        [self.contentView addSubview:_costShow];
        [_costShow release];
        self.collectBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.collectBtn.frame = CGRectMake(SCREEN_WIDTH - 40, 30, 30, 30);
        [self.collectBtn setImage:[UIImage imageNamed:@"iconfont-xin@2x"] forState:(UIControlStateNormal)];
        [self.collectBtn setImage: [UIImage imageNamed:@"424BF5D656AFF3CCBFB2C5585C937610@2x"]forState:(UIControlStateSelected)];
        self.collectBtn.backgroundColor = [UIColor whiteColor];
        [self.collectBtn setTintColor:[UIColor grayColor]];
        self.collectBtn.adjustsImageWhenHighlighted = YES;
        [self.collectBtn addTarget:self action:@selector(collect:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:self.collectBtn];
        self.userImgView = [[UIImageView alloc] init];
        _userImgView.backgroundColor = [UIColor redColor];
       
        [self.contentView addSubview:_userImgView];
        [_userImgView release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 200);
    _title.frame = CGRectMake(80, _imgView.frame.size.height, SCREEN_WIDTH-80, 40);
    _styleShow.frame = CGRectMake(80, _title.frame.origin.y + 40, 50, 30);
    _typeShow.frame = CGRectMake(130, _styleShow.frame.origin.y, 50, 30);
    _areaShow.frame = CGRectMake(180, _typeShow.frame.origin.y, 100, 30);
    _costShow.frame = CGRectMake(280, _typeShow.frame.origin.y, 100, 30);
    _userImgView.frame = CGRectMake(5, 205, 60, 60);
    _userImgView.layer.cornerRadius = 30;
    _userImgView.clipsToBounds = YES;
    self.collectBtn.selected = [[DataBaseManager shareInstance] selectCaseBytitle:self.title.text];
}
//点击收藏
-(void)collect:(UIButton *)btn
{
    
    if (btn.selected) {
        [[DataBaseManager shareInstance] deleteBytitle:self.title.text];
    }else{
        [[DataBaseManager shareInstance] insertData:self.title.text photo:self.mId];
    }
    btn.selected = !btn.selected;
    // 关键帧动画 改变view缩放属性
    CAKeyframeAnimation *likeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    // 设置关键帧的值,values是数组类型
    likeAnimation.values = @[@(0.1),@(1.0),@(1.5)];
    likeAnimation.duration = 0.2;
    [btn.layer addAnimation:likeAnimation forKey:@"key"];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
